#pragma once

#include "UMLClassifierShape.h"

#include "../uml/Classifier.h"

namespace uml {

const bool UMLClassifierShape::isIndentForVisibility_default_ = false;
const bool UMLClassifierShape::isDoubleSided_default_ = false;
UMLClassifierShape::UMLClassifierShape(const QString& umlType)
    : UMLCompartmentableShape(umlType) {}

void UMLClassifierShape::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    UMLCompartmentableShape::fromJson(json, errorList);
    modelElement_ = JsonSerializable::create<Classifier>(json.value("modelElement"), errorList);

    isIndentForVisibility_ = json.value("isIndentForVisibility").toBool(isIndentForVisibility_default_);
    isDoubleSided_ = json.value("isDoubleSided").toBool(isDoubleSided_default_);
}

void UMLClassifierShape::toJson(QJsonObject& json) {
    UMLCompartmentableShape::toJson(json);
    if (modelElement_) {
        QJsonObject modelElement_json;
        modelElement_->toJson(modelElement_json);
        json.insert("modelElement", modelElement_json);
    }
    if (isIndentForVisibility_ != isIndentForVisibility_default_) {
        json.insert("isIndentForVisibility", isIndentForVisibility_);
    }
    if (isDoubleSided_ != isDoubleSided_default_) {
        json.insert("isDoubleSided", isDoubleSided_);
    }
}

/// <summary>
/// modelElement getter
/// Restricts UMLClassifierShapes to showing exactly one Classifier.
/// </summary>
shared_ptr<Classifier> UMLClassifierShape::modelElement() const {
    return modelElement_;
}

/// <summary>
/// modelElement setter
/// Restricts UMLClassifierShapes to showing exactly one Classifier.
/// </summary>
void UMLClassifierShape::setModelElement(shared_ptr<Classifier> value) {
    modelElement_ = value;
}

/// <summary>
/// isIndentForVisibility getter
/// For modelElements that are shown with feature compartments, indicates whether
/// features are shown indented under visibility headings.
/// </summary>
bool UMLClassifierShape::isIndentForVisibility() const {
    return isIndentForVisibility_;
}

/// <summary>
/// isIndentForVisibility setter
/// For modelElements that are shown with feature compartments, indicates whether
/// features are shown indented under visibility headings.
/// </summary>
void UMLClassifierShape::setIsIndentForVisibility(bool value) {
    isIndentForVisibility_ = value;
}

/// <summary>
/// isDoubleSided getter
/// For modelElements that are Classes with true as a value for isActive that are
/// shown as rectangles, indicates whether the vertical sides shall be rendered as
/// double lines.
/// </summary>
bool UMLClassifierShape::isDoubleSided() const {
    return isDoubleSided_;
}

/// <summary>
/// isDoubleSided setter
/// For modelElements that are Classes with true as a value for isActive that are
/// shown as rectangles, indicates whether the vertical sides shall be rendered as
/// double lines.
/// </summary>
void UMLClassifierShape::setIsDoubleSided(bool value) {
    isDoubleSided_ = value;
}

} // namespace uml
